package com.gw.quotes.activity;

import net.tsz.afinal.annotation.view.ViewInject;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.Toast;
import com.gw.quotes.R;
import com.gw.quotes.entity.business.GetInformationListEntity.Information;
import com.gw.quotes.util.CommonTools;

public class NoticeDetailActivity extends BaseActivity {

	@ViewInject(id = R.id.webview)
	private WebView webview;
	@ViewInject(id = R.id.back_img, click = "back")
	private ImageView back_img;

	private Information information = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_notice_detail);
		getData();
		initView();
	}

	private void getData() {
		Intent intent = getIntent();
		information = (Information) intent.getSerializableExtra("itemInfo");
	}

	@SuppressLint("NewApi")
	private void initView() {
		if (information==null) {
			CommonTools.showShortToast(this, "参数传递异常");
		}

		WebSettings webSettings = webview.getSettings();
		webSettings.setJavaScriptEnabled(true);
		// webSettings.setPluginsEnabled(true);
		webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
		webSettings.setPluginState(PluginState.ON);
		webSettings.setAllowFileAccess(true);
		webSettings.setSupportZoom(true);
		webSettings.setDisplayZoomControls(true);
		// webSettings.setUserAgent(0);
		webSettings.setAppCacheEnabled(true);
		// webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
		webSettings.setLoadWithOverviewMode(true);
		webSettings.setUseWideViewPort(true);

		CommonTools.showShortToast(this, "加载中…");

		webview.setOnKeyListener(new View.OnKeyListener() {
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (event.getAction() == KeyEvent.ACTION_DOWN) {
					if (keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack()) { // 表示按返回键
						webview.goBack(); // 后退
						return true; // 已处理
					}
				}
				return false;
			}
		});
		webview.loadUrl(information.getUrl());

	}

	public void back(View v) {
		finish();
	}

}
